using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Rally_Dekstop
{
    public partial class DefectFilterSelector : Form
    {
        public string queryString = string.Empty;
        public string Username = string.Empty;
        private DateTime Date = new DateTime();
        private GUIDateSelector SelectDate = null;
        public bool ShowResults = false;

        public DefectFilterSelector()
        {
            InitializeComponent();
           

            cmb_StateValue.Items.Add("All");
            foreach (string state in RallyDesk.CURRENTWORKSPACE.WorkSpaceSpecifics.Defect.States)
            {
                if (state.Trim().Length > 0)
                {
                    cmb_StateValue.Items.Add(state);
                }
            }
            foreach (string user in RallyDesk.CURRENTWORKSPACE.WorkSpaceSpecifics.Defect.Users)
            {
                if (user.Trim().Length > 0)
                {
                    cmb_UsersValue.Items.Add(user);
                }
            }


        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
                
                if (cmb_StateValue.Text == "All")
                {
                    queryString = "(Owner " + cmb_UsersOperator.Text + " \"" + cmb_UsersValue.Text + "\")";
                }
                else
                {
                    queryString = "((Owner " + cmb_UsersOperator.Text + " \"" + cmb_UsersValue.Text + "\") and (State " + cmb_StateOperator.Text + " \"" + cmb_StateValue.Text + "\"))";
                }

                RallyDesk.DefectFilterUsername = cmb_UsersValue.Text;
                RallyDesk.DefectFilterUsernameOperator = cmb_UsersOperator.Text;
                RallyDesk.DefectFilterState = cmb_StateValue.Text;
                RallyDesk.DefectFilterStateOperator = cmb_StateOperator.Text;
                RallyDesk.DefectQueryString = queryString;

                this.DialogResult = DialogResult.OK;
        }

       

        private void DefectFilterSelector_Load(object sender, EventArgs e)
        {
           
            cmb_UsersValue.Text = RallyDesk.DefectFilterUsername; 
            cmb_UsersOperator.Text = RallyDesk.DefectFilterUsernameOperator;
            cmb_StateValue.Text = RallyDesk.DefectFilterState; 
            cmb_StateOperator.Text = RallyDesk.DefectFilterStateOperator;
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //if(SelectDate ==null)
            //   SelectDate = new GUIDateSelector();
            //SelectDate.ShowDialog();
            //lbl_Date.Text = SelectDate.SelectedDate.Date.ToShortDateString();
            //Date = SelectDate.SelectedDate;
            //if (lbl_Date.Text.Length > 0)
            //    this.comboBox2.Enabled = true;
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            this.ShowResults = true;
            this.btn_OK.PerformClick();
        }
    }
}